var form;
var tableIns;
var ctxPath = '/'
$(function () {
    layui.config({
        base: ctxPath + 'lib/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index'//主入口模块
    }).use(['index', 'table', 'form'], function () {
        var table = layui.table;
        form = layui.form;
        // 渲染表格
        tableIns = table.render({
            elem: '#table',
            toolbar: '#table-title',
            url: 'currUserPager',
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'name', title: '用户名', align: 'center'},
                {field: 'sessionid', title: '登录ID', align: 'center'},
                {field: 'right', title: '操作', toolbar: '#table-toolbar', align: 'center'},
            ]],
            done: function (res, curr, count) {
                // merge(res);
                // $('tr').css({'background-color': '#009688', 'color': '#fff'});//表头样式修改
                document.getElementById("count_user").innerHTML=res.count;
            },
            request: {
                pageName: 'page' //页码的参数名称，默认：page
                , limitName: 'limit' //每页数据量的参数名，默认：limit
            }
        });
        //监听行工具事件
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'kickOut') {
                kickOut(data)
            }
        });
    });
})

/**
 * 打开编辑窗口
 * @param data layui中保存的table中的对应的此条信息
 */
function kickOut(data) {
    layer.confirm('您确定要踢出' + data.name + '用户么', function () {
        $.ajax({
            type: "DELETE",
            data: {
                "name":data.name,
                "sessionid": data.sessionid
            },
            url: ctxPath + "security/currUser/kickOut",
            complete: function () {
                tableReload()
            }
        });
    });
}

function tableReload() {
    tableIns.reload({
        page: {
            curr: 1 //重新从第 1 页开始
        }
    });
}